<?php
  require_once 'DB.php';
  include_once("./libraries/db.inc.php");
  include_once("./libraries/util.inc.php");
  include_once("./libraries/authentication.inc.php");
  include_once("./queries/prov.inc.php");
  include_once("./libraries/recordset.inc.php");

  session_start();
  sessionAuthenticate("login.php");  

  $dataIndex = "provMachineSearchForFileByName";
  $displayPage = 1;

  // Process the GET variables
  foreach($_GET as $varName => $value) {
    if ($varName == "dP") {
      $displayPage = $value;
    }
    if ($varName == "fileName") {
      if(ereg("^( *)$", $value)) {
        $fileName = "";
        $_SESSION["{$dataIndex}"]["fileName"] = "";
      }
      else {
        $fileName = $value;
        $_SESSION["{$dataIndex}"]["fileName"] = $fileName;
      }
    }
    if ($varName == "filePath") {
      if(ereg("^( *)$", $value)) {
        $filePath = "";
        $_SESSION["{$dataIndex}"]["filePath"] = "";
      }
      else {
        $filePath = $value;
        $_SESSION["{$dataIndex}"]["filePath"] = $filePath;
      }
    }
  }

  $username = $_SESSION["loginUsername"];
  $fileName = $_SESSION["{$dataIndex}"]["fileName"];
  $filePath = $_SESSION["{$dataIndex}"]["filePath"];
  $title = "Find Files by Name and/or Path";
  $message = "Your files with Name including $fileName and Path including $filePath.<br>Select a File Id.";

  // Connect to the database
  $connection = DB::connect($dsn, $options);
  if (DB::isError($connection)) {
    trigger_error($connection->getMessage(), E_USER_ERROR);
  }

  // Run the query
  $rs = filesByNameAndPath($connection, $fileName, $filePath, $username, 
                           $displayPage);

  $connection->disconnect();

  $rs->setLinkParams(0, array("gjid"), array(0), "provMachinesByFileAction.php");

  $rs->printNavigablePage($title, $message, $displayPage, 
                          "./provMachineSearchForFileByName.php");

  cdbFinishPage();

?>
